﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Solr {
    //[Serializable]
    public class SolrQueryFacet {
        /// <summary>
        /// 使用字段值统计，得到查询结果中，符合每个字段值的文档数量
        /// </summary>
        public IEnumerable<string> Fields { get; set; }

        /// <summary>
        /// 使用条件统计，得到查询结果中每个统计条件的文档数量
        /// </summary>
        public IEnumerable<string> Query { get; set; }

        /// <summary>
        /// 文档数量>=指定值的统计项才返回
        /// </summary>
        public int MinCount { get; set; }

        /// <summary>
        /// 最多返回的筛选项数量
        /// </summary>
        public int Limit { get; set; }

        public IEnumerable<string> BuildUrlParameters() {
            yield return "facet=true";

            yield return "facet.sort=index";

            if (Limit > 0)
                yield return string.Format("facet.limit={0}", Limit);

            if (Fields != null)
                foreach (var _ in Fields)
                    yield return string.Format("facet.field={0}", _);

            if (Query != null)
                foreach (var _ in Query)
                    yield return string.Format("facet.query={0}", _);

            if (MinCount > 0)
                yield return string.Format("facet.mincount={0}", MinCount);
        }
    }
}